﻿@using DTcms.Common;
@{
    ViewBag.Title = "内容回收站";
    List<SelectListItem> propertyList = new List<SelectListItem>() {
        new SelectListItem(){ Text="所有属性", Value=""},
        new SelectListItem(){ Text="可评论", Value="isMsg"},
        new SelectListItem(){ Text="置顶", Value="isTop"},
        new SelectListItem(){ Text="推荐", Value="isRed"},
        new SelectListItem(){ Text="热门", Value="isHot"},
        new SelectListItem(){ Text="幻灯片", Value="isSlide"}
    };
    int channel_id = ViewBag.channel_id;
}
<div class="pageheader">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
            <li><a href="javascript:;">内容管理</a> </li>
            <li><a href="javascript:;">内容回收站</a> </li>
        </ul>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card layui-tab">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="menu-list">
                        <div class="layui-inline">
                            <div class="layui-input-inline mr0">
                                <input id="txtKeywords" class="layui-input" type="text" placeholder="输入关键字" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" id="btnSearchAuth" data-type="btnSearch">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-btn-group">
                            <a data-type="btnAudit" class="layui-btn"><i class="iconfont icon-survey"></i><span> 还原</span></a>
                            <a data-type="btnDelete" class="layui-btn"><i class="iconfont icon-delete"></i><span> 彻底删除</span></a>
                        </div>
                        <div class="menu-select">
                            <select class="select" name="ddlCategoryId" lay-filter="btnSearch" url="/webapi/categoryJson?id=@channel_id" selectValue="" promtion="所有类别..."><option value="">所有类别...</option></select>
                            @Html.DropDownList("ddlProperty", new SelectList(propertyList, "Value", "Text"), new { @lay_filter = "btnSearch" })
                        </div>
                    </div>
                </div>
            </div>
            <table class="layui-table" lay-data="{page:true, id:'ltable'}" lay-filter="ltable">
                <thead>
                    <tr>
                        <th lay-data="{checkbox:true}"></th>
                        <th lay-data="{field:'title',templet:'#titleTpl'}">标题</th>
                        <th lay-data="{field:'categoryTitle'}">所属类别</th>
                        <th lay-data="{field:'call_index'}">left</th>
                        <th lay-data="{field:'status',templet:'#switchTpl'}">状态</th>
                        <th lay-data="{field:'is_msg',templet:'#btnTools'}">属性</th>
                        <th lay-data="{field:'add_time'}">发布时间</th>
                        <th lay-data="{field:'sort_id'}">排序</th>
                        <th lay-data="{templet: '#barDemo'}">操作</th>
                    </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a href="../article/article_edit?action=@DTEnums.ActionEnum.Edit&channel_id=@channel_id&id={{d.id}}" class="layui-btn layui-btn-primary layui-btn-xs">修改</a>
</script>
<script type="text/html" id="titleTpl">
    <a href="../article/article_edit?action=@DTEnums.ActionEnum.Edit&channel_id=@channel_id&id={{d.id}}" class="layui-table-link">{{ d.title }}</a>
</script>
<script type="text/html" id="btnTools">
    <div class="btn-tools">
        <a href="javascript:;" class="msg {{ d.is_msg==1?'selected':''}}" title="{{ d.is_msg==1?'取消评论':'设置评论'}}" onclick="setStatus({{d.id}}, 'lbtnIsMsg', this);"><i class="iconfont icon-comment"></i></a>
        <a href="javascript:;" class="top {{ d.is_top==1?'selected':''}}" title="{{ d.is_msg==1?'取消置顶':'设置置顶'}}" onclick="setStatus({{d.id}}, 'lbtnIsTop', this);"><i class="iconfont icon-top"></i></a>
        <a href="javascript:;" class="red {{ d.is_red==1?'selected':''}}" title="{{ d.is_msg==1?'取消推荐':'设置推荐'}}" onclick="setStatus({{d.id}}, 'lbtnIsRed', this);"><i class="iconfont icon-good"></i></a>
        <a href="javascript:;" class="hot {{ d.is_hot==1?'selected':''}}" title="{{ d.is_msg==1?'取消热门':'设置热门'}}" onclick="setStatus({{d.id}}, 'lbtnIsHot', this)"><i class="iconfont icon-hot"></i></a>
        <a href="javascript:;" class="pic {{ d.is_slide==1?'selected':''}}" title="{{ d.is_msg==1?'取消幻灯片':'设置幻灯片'}}" onclick="setStatus({{d.id}}, 'lbtnIsSlide', this);"><i class="iconfont icon-pic"></i></a>
    </div>
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="显示|隐藏" lay-filter="status" {{ d.status == 0 ? 'checked' : '' }}>
</script>
@section Scripts{
    <script type="text/javascript">
        layui.use(['table','cascadeSelect','cmswh'], function () {
            var table = layui.table, form = layui.form, cascadeSelect = layui.cascadeSelect,cmswh=layui.cmswh, $ = layui.jquery;
            cascadeSelect.init('ddlCategoryId', false);

            cmswh.dataBind('RecycleList?channel_id=@channel_id');
            var active = {
                btnAudit: function () {
                    cmswh.batOperate('RecycleAudit?channel_id=@channel_id', 'id', "还原后前台将显示该信息，确定继续吗？");
                },
                btnDelete: function () {
                    cmswh.batOperate('RecycleDelete?channel_id=@channel_id', 'id');
                },
                btnSearch: function () {
                    table.reload('ltable', { page: { curr: 1 }, where: getcond() });
                }
            };
            //监听状态操作
            form.on('switch(status)', function (obj) {
                cmswh.request("ArticleSwitch?channel_id=@channel_id", "POST",{ id: this.value, status: obj.elem.checked });
            });
            form.on('select(btnSearch)', function (data) {
                var type = "btnSearch";
                active[type] ? active[type].call(this) : '';
            });
            $('.layui-inline .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            /*拼接条件返回postdata*/
            function getcond() {
                var keywords = $("#txtKeywords").val();
                var categoryId = $("select[name=ddlCategoryId]").val();
                var propertyType = $("#ddlProperty").val();
                var postdata = { keywords: keywords, category_id: categoryId, property: propertyType, channel_id:@channel_id };
                return postdata;
            }
            window.setStatus=function(id, objId, obj) {
                $.ajax({
                    url: "ArticleStatus?channel_id=@channel_id",
                    cache: false,
                    type: "POST",
                    dataType: "json",
                    data: { id: id, cmdName: objId},
                    success: function (data) {
                        if (data.status == 1) {
                            layer.msg(data.msg, { icon: 6 });
                            if ($(obj).hasClass("selected")) {
                                $(obj).removeClass("selected");
                            }
                            else {
                                $(obj).addClass("selected");
                            }
                        } else {
                            layer.alert(data.msg, { icon: 5 });
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert('状态：' + textStatus + '；出错提示：' + errorThrown, { icon: 5 });
                    }
                });
            }
        });
    </script>
}